<template>
  <div>
    <div class="fu" v-if="!token">
      <img
        class="im"
        src="http://liufusong.top:8080/img/profile/bg.png"
        alt=""
      />
      <div class="idcard">
        <div class="user">
          <img
            class="tu"
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ffiles.lkkcdn.com%2FImages%2F201811%2F6Ww215420301763645.jpg&refer=http%3A%2F%2Ffiles.lkkcdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670579791&t=d71d636106f8c6ba697eb963ae270d5e"
            alt=""
          />
          <div class="user1">游客</div>
          <div class="user1">
            <van-button type="primary" to="/login">登录</van-button>
          </div>
        </div>
      </div>
    </div>
    <div class="fu" v-else>
      <img
        class="im"
        src="http://liufusong.top:8080/img/profile/bg.png"
        alt=""
      />
      <div class="idcard">
        <div class="user">
          <img
            class="tu"
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ffiles.lkkcdn.com%2FImages%2F201811%2F6Ww215420301763645.jpg&refer=http%3A%2F%2Ffiles.lkkcdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670579791&t=d71d636106f8c6ba697eb963ae270d5e"
            alt=""
          />
          <div class="user1">{{username}}</div>
          <div class="user1">
            <van-button type="primary" to="/login" @click="tuichu">退出</van-button>
          </div>
        </div>
      </div>
    </div>
    <div class="user1">
      <van-grid :column-num="3">
        <van-grid-item icon="star-o" text="我的收藏" @click="clickfn" />
        <van-grid-item icon="wap-home-o" text="我的出租" @click="clickfn1"/>
        <van-grid-item icon="clock-o" text="看房记录" />
      </van-grid>
      <van-grid :column-num="3">
        <van-grid-item icon="debit-pay" text="成为房主" />
        <van-grid-item icon="contact" text="个人资料" />
        <van-grid-item icon="service-o" text="联系我们" />
      </van-grid>
    </div>
    <div class="ad">
      <img src="http://liufusong.top:8080/img/profile/join.png" alt="" />
    </div>
  </div>
</template>

<script>
import { getToken, delToken } from '@/utils/storage'
import { getmsg } from '@/api/user'
export default {
  data () {
    return {
      username: ''
    }
  },

  computed: {
    token () {
      return getToken()
    }
  },
  async created () {
    const { body } = await getmsg()
    console.log(body)
    this.username = body.nickname
  },
  methods: {
    tuichu () {
      delToken()
      this.$router.push('/login')
    },
    clickfn () {
      if (getToken()) {
        this.$router.push('/collect')
      } else {
        this.$router.push('/login')
      }
    },
    clickfn1 () {
      if (getToken()) {
        this.$router.push('/rent')
      } else {
        this.$router.push('/login')
      }
    }
  }
}

</script>

<style>
* {
  box-sizing: border-box;
}
.fu {
  min-height: 300px;
  position: relative;
}
.im {
  width: 100%;
}
.img {
  border-style: none;
}
.idcard {
  position: absolute;
  background-color: #fff;
  width: 85%;
  height: 55%;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px 3px #ddd;

  margin: 50px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 13px;
}
.user {
  position: relative;
  transform: translateY(-50%);
  border-radius: 50%;
  width: 70px;
  height: 70px;
  border: 5px solid #f5f5f5;
  display: inline-block;
  box-shadow: 0 2px 2px #bdbdbd;
}
.tu {
  width: 100%;
  border-radius: 50%;
}
.user1 {
  margin-top: 15px;
}
.ad {
  width: 345px;
  height: 85px;
  margin: 10px auto 0;
}
.ad img {
  width: 100%;
}
</style>
